#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
typedef struct TreeNode
{
	char val;
	struct TreeNode* left;
	struct TreeNode* right;
}TreeNode;
TreeNode* make_a_tree(char arr[], int* x)
{
	if (arr[*x] == 0)
		return;
	if (arr[*x] == '#')
		return NULL;
	TreeNode* root = (TreeNode*)malloc(sizeof(TreeNode));
	root->val = arr[*x];
	(*x)++;
	root->left = make_a_tree(arr,x);
	(*x)++;
	root->right = make_a_tree(arr, x);
	return root;
}
void BinaryTreePrevOrder(TreeNode* root)
{
	if (root != NULL)
	{
		printf("%c", root->val);
		BinaryTreePrevOrder(root->left);
		BinaryTreePrevOrder(root->right);
	}
	else
		printf("#");

}
int find_leaf(TreeNode* root)
{
	if (root == NULL)
		return 0;
	if (root->left == root->right)
		return 1;
	
	return find_leaf(root->left)+ find_leaf(root->right);
}
void reverse(TreeNode* root)
{
	
	if (root == NULL)
		return;
	TreeNode* tmp = root->left;
	root->left = root->right;
	root->right = tmp;
	reverse(root->left);
	reverse(root->right);
}
void postOrder(TreeNode* root)
{
	if (root == NULL)
		printf("#");
	else
	{
		postOrder(root->left);
		postOrder(root->right);
		printf("%c", root->val);
	}
}
int main()
{
	char arr[100] = { 0 };
	scanf("%s", arr);
	int i = 0;	
	TreeNode* tree=make_a_tree(arr,&i);
	//postOrder(tree);
	//BinaryTreePrevOrder(tree);
	int x = find_leaf(tree);
	printf("%d\n", x);
	reverse(tree);
	postOrder(tree);
	//BinaryTreePrevOrder(tree);
}